
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# DISCLAIMER AND GENERAL INFORMATION
#
# File: SI1_descriptive_stats.R
# Purpose: Produces descriptive statistics in section SI1
# Date: June 2025
# Data: pulled through 00_data_prep.R
#
# See 00_data_prep.R for technical disclaimer on R versions
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# Load data
source("00_data_prep.R")


# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# (A) Descriptive statistics (Table SI1) ----
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# Change group labels 
full <- full %>%
  mutate(sample=case_when(sample=="Northern England" ~ "Yorkshire and Cumbria",
                          sample!="Northern England" ~ sample,
                          .default=NA)) %>%
  mutate(sample=factor(sample, levels=c("General population", "Yorkshire and Cumbria", "Scotland", "Wales"), 
                       ordered=FALSE)) %>%
  as_tibble()

# Table SI1
tab <- datasummary((`Sample`=sample) * 
              ((`Age group: 1 ($<$21 y) to 7 ($>$70 y)`=age) + 
              (`Female: 0 (male) to 1 (female)`=female) + 
              (`Education group: 1 (no qual) to 6 (PhD)`=education) + 
              (`Income (8 levels):` = income) +
              (`Employment sector (21 levels):` = empl_sector) +
              (`Climate concern: 1 (not at all) to 4 (very)`=cc_concern) + 
              (`Urban share: Percent (self-reported)`=urban) + 
              (`Fossil fuel vicinity: 0 (no) to 1 (yes)`=ff_vicinity))
              ~ N + Mean + SD + Min * Arguments(fmt = "%.0f") + Max * Arguments(fmt = "%.0f"), 
              data=full, 
              title=c("Summary statistics for different samples"),
              output="tinytable") %>%
              theme_tt("placement", latex_float="h!")

tinytable::save_tt(tab, "./tables/SI1_main_desc.tex", overwrite=TRUE)


# =============================================================
#                         END OF FILE
# =============================================================


